﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Jumpton.Data;
using System.IO;
using System.Data;
using Jumpton.SFA.Server.BusinessRule;

namespace BusinessRule.ImportExcel
{
    public class Import_Contact_InfoManager : BusinessLogic
	{
        public void ImportContact(string excelPath,string sheetName,string colNames,string sqlTableName,string sqlTableColNames,string sqlWhere)
        {
            SqlData.ExecuteSP("sp_ExcelOutIn", "In", sqlWhere, excelPath, sheetName, colNames, sqlTableName, sqlTableColNames);
        }

        public void ImportContact(DataTable dt, decimal domain_id, string personName, decimal personId)
        {
            string sql= string.Empty;
            long date = GetDateTimeLong(DateTime.Now);
            //string last_updater = ge
            foreach (DataRow item in dt.Rows)
            {
                decimal id = decimal.Parse(personId + DateTime.Now.ToString("yyyyMMddHHmmss") + new Random().Next(1000, 9999));
                sql = string.Format(@"insert into CUSTOMERS (CODE,NAME,GEO_LEVEL_CODE,
                                LOCAL_LEVEL1_CODE,ORG_ID,DOMAIN_ID,PARENT_CODE,ACTIVE,LAST_UPDATER,
                                LAST_UPDATE_TIME,CREATE_TIME,ID)
                                values ('{0}','{1}','{2}','{3}',{4},'{5}','{6}',1,'{7}',{8},{8},{9})",
                                               item[0], item[1], item[2], item[3], 
                                               item[4],domain_id,"default",personName,date,id);
                SqlData.ExecuteSql(sql);
                sql = string.Format(@"insert into CONTACT_INFO (ADDRESS_LINE,TELEPHONE,FAX,
                                E_MAIL,SLOG_CODE,CUSTOMER_ID,LAST_UPDATER,LAST_UPDATE_TIME,ACTIVE) 
                                values ('{0}','{1}','{2}','{3}','{4}',{5},'{6}','{7}',1)",
                                               item[5],item[6],item[7],item[8],item[9],id,personName,date);
                SqlData.ExecuteSql(sql);
            }
        }
	}
}
